package iedcyt.acute.controller.listeners.signComparison;

import iedcyt.acute.businessServices.ViewLogger;
import iedcyt.acute.model.SignComparisonModel;
import iedcyt.acute.view.SignComparisionView;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;

public class Corps1KeyDownListener extends SignComparisonCommonListener implements Listener {

	
	
	public Corps1KeyDownListener(SignComparisionView view,
			SignComparisonModel model) {
		super(view, model);
		this.toolTip = "ACCIONES PARA DIRECCIONES 1\n- l: liga el corp a la firma" +
		"\n- d: desliga el corp de la firma" +
		"\n- h: imprime la ayuda";
	}

	public void handleEvent(Event event) {

		Integer idCorp = _model.getSelected_sign1IdCorp();
		
		char press = ("" + event.character).toLowerCase().toCharArray()[0];
		
		if (idCorp == null)
			press = Character.MIN_VALUE;

		// Al pulsar 'l' se liga el centro a la firma
		if (press == 'l') {
			_model.bindCorpToSign1();
			updateView();
		} else if (press == 'd') {
			_model.unbindCorpFromSign1();
			updateView();
		}  else if (press == 'h') {
			ViewLogger.getInstance().info(toolTip);
		}
	}

	private void updateView() {
		
		_view.loadCenters2(_model.getSign2Centers(), _model.isSign2CentersWarning());
		_view.loadCorps2(_model.getSign2Corps(), _model.isSign2CorpsWarning());
		_view.loadCorps1(_model.getSign1Corps(), _model.isSign1CorpsWarning());
		_view.loadCenters1(_model.getSign1Centers(), _model.isSign1CentersWarning());
		
		_view.compareTables();
		
	}

}
